import { defineStore } from "pinia";
import { getAllDMDataApi, getEditInfoApi, searchInfoApi } from '@/service/dormitory-manger'
export const useDMStore = defineStore('dm_store', {
    state() {
        return {
            tableData: [],
            dmInfo: null,
            isSearchStatus: false,  // 是否是搜索状态
            selectionIds: [],   // 批量删除的id值
        }
    },
    actions: {
        // 获取所有的信息记录
        async getAllDMData() {
            const res = await getAllDMDataApi();
            // 判断数组中是否存在数据
            if (this.tableData.length) this.tableData = []; // 清空数组
            this.tableData = res.data.data;

        },
        // 根据id获取某一条信息记录
        async getDmInfo(id) {
            const res = await getEditInfoApi(id)
            this.dmInfo = res.data.data
        },
        // 搜索宿管信息
        async searchInfo(key, value) {
            const res = await searchInfoApi(key, value);
            this.tableData = [];
            if (!res.data.code) return;
            this.tableData.push(res.data.data);
        }
    }
})